import React, { useState, Suspense } from 'react';

import { Breadcrumb, Layout, Menu, theme } from 'antd';
const { Header, Content, Footer, Sider } = Layout;
import Loading from './components/loading/Loading'
import { Outlet, useLocation, useNavigate } from 'react-router-dom'
import { homeelse } from './router';

function App() {
  const [collapsed, setCollapsed] = useState(false);
  const {
    token: { colorBgContainer, borderRadiusLG },
  } = theme.useToken();
  const nav = useNavigate()
  const { pathname } = useLocation()
  const route = (arr: any) => {
    return arr.map((item: any) => {
      return {
        key: item.path,
        label: item.title,
        icon: item.icon,
        children: item.children ? route(item.children) : null
      }
    })
  }
  const items = route(homeelse)
  return (
    <div>
      <Layout style={{ minHeight: '100vh' }}>
        <Sider collapsible collapsed={collapsed} onCollapse={value => setCollapsed(value)}>
          <div className="demo-logo-vertical" />
          <Menu onClick={({ key }) => nav(key)} theme="dark" defaultSelectedKeys={[pathname]} mode="inline" items={items} />
        </Sider>
        <Layout>
          <Header style={{ padding: 0, background: colorBgContainer }} />
          <Content style={{ margin: '0 16px' }}>
            <Breadcrumb style={{ margin: '16px 0' }} items={[{ title: 'User' }, { title: 'Bill' }]} />
            <div
              style={{
                padding: 24,
                minHeight: 360,
                background: colorBgContainer,
                borderRadius: borderRadiusLG,
              }}
            >
              <Suspense fallback={<Loading />}>
                <Outlet></Outlet>
              </Suspense>
            </div>
          </Content>
          <Footer style={{ textAlign: 'center' }}>
            Ant Design ©{new Date().getFullYear()} Created by Ant UED
          </Footer>
        </Layout>
      </Layout>


    </div>
  )
}

export default App
